package com.sptan.ssmp.controller;


import com.sptan.ssmp.dto.AdminUserDTO;
import com.sptan.framework.core.ResultEntity;
import com.sptan.ssmp.service.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * The type Admin user controller.
 */
@RestController
@RequestMapping("/api/v1/admin-user")
@RequiredArgsConstructor
@Tag(name = "admin-user", description = "管理员用户控制器")
public class AdminUserController {
    private final AdminUserService adminUserService;

    /**
     * Register response entity.
     *
     * @param id the id
     * @return the response entity
     */
    @PostMapping("/detail/{id}")
    @Operation(summary = "详情", description = "根据ID查看详情")
    @Parameters({
        @Parameter(in = ParameterIn.HEADER, name = "Authorization", description = "标识用户信息的请求头", required = true),
        @Parameter(in = ParameterIn.PATH, name = "id", description = "ID", required = true)
    })
    public ResponseEntity<ResultEntity<AdminUserDTO>> register(@PathVariable(name = "id") Long id) {
        ResultEntity<AdminUserDTO> detail = adminUserService.detail(id);
        return ResponseEntity.ok(detail);
    }

    /**
     * 保存.
     *
     * @param dto the dto
     * @return the response entity
     */
    @PostMapping("/save")
    @Operation(summary = "保存", description = "保存对象,包括新增和修改")
    @Parameters({
        @Parameter(in = ParameterIn.HEADER, name = "Authorization", description = "标识用户信息的请求头", required = true)
    })
    public ResponseEntity<ResultEntity<AdminUserDTO>> save(@Validated @RequestBody AdminUserDTO dto) {
        ResultEntity<AdminUserDTO> resultEntity = adminUserService.save(dto);
        return ResponseEntity.ok(resultEntity);
    }


}
